'''
Created on 2014-4-20

@author: shen
'''

import urllib
import simplejson as json

_metaclass_=type

REQUEST_URL = 'http://112.124.1.3:8004'

    #usage demo
    
#    if __name__ == '__main__':
#    #   20 record in a page , from page 0 to page end
#    end=10
#    g = get_ASIN()
#    ASIN_list = []
#    for i in range(0,end):
#        ASIN_list.extend(g.get(i))
#        
#    print ASIN_list[0]


class get_ASIN:

    
    def get(self ,category,i):
        '''
        get specified commodity given
        category or asin
        '''
        all_category_url = 'api/commodity'
    
        #take info of page i
        specified_cate_data = json.loads(urllib.urlopen('?'.join([
            '/'.join([REQUEST_URL, all_category_url]),
            urllib.urlencode({
            'category_name': category,
            'field': ['ASIN'],
            'page':i
            })])).read())
        #take specified asin to get detail data
        #get all field also can get specify-field data
        
        list = []
        for item in specified_cate_data:
            list.append(item['ASIN'])
            
        return list
    

    
    
def categoay_name():
    return 'Cell Phones $ Accessories>Cell Phones>Contract Cell Phones'
